from selenium.common import TimeoutException
from selenium.webdriver import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from core.keywords import Keywords
from utils.step_logger import step_logger
import logging

class BusinessKeywords(Keywords):

    def find2(self,by,value):
        wait=WebDriverWait(self.driver,10)
        locator=by,value
        try:
            return wait.until(EC.presence_of_element_located(locator))
        except TimeoutException:
            logging.info(f"❌❌❌❌❌元素定位失败,元素定位信息为{locator}")

    """
    """
    @step_logger
    def login(self,step):
        self.driver.get("http://192.168.10.130/login?redirect=%2Findex")

        login_data=eval(step["data"])
        self.find2("xpath","//input[@placeholder='账号']").send_keys(login_data["username"])
        self.find2("xpath", "//input[@placeholder='密码']").send_keys(login_data["password"])
        self.find2("xpath", "//input[@placeholder='验证码']").send_keys(login_data["code"])
        self.find2("xpath", "//span[.='登 录']").click()






